﻿Public Class Form1NG
    Public usr As String
    Public ty As String
    Public current_procedure_No As Integer
    Public current_procedure_Name As String
    Dim objReasonMst As New clsReasonMst
    Dim objGtProcedureOperatedNgDetails As New clsGtProcedureOperatedNgDetails
    Dim dt As DataTable
    Private Sub Form1NG_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = current_procedure_Name & Me.Text
        GroupBox1.Text = current_procedure_Name & GroupBox1.Text
        setData()
    End Sub
    Public Sub setData()
        dt = objGtProcedureOperatedNgDetails.getGtProcedureOperatedNgDetials(ty, "'1'", current_procedure_No.ToString(), 1)
        dt.Columns.Add("oper_type_name")
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If row("oper_type") = "0" Then
                    row("oper_type_name") = "骨架板"
                Else
                    row("oper_type_name") = "法兰板"
                End If
            Next
        End If
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dt
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim chklstChecked As Boolean = False
            For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                    chklstChecked = True
                End If
            Next
            If chklstChecked = False Then
                MsgBox("请选择不合格原因！")
                chkNg_Reason.Select()
                Exit Sub
            End If
            Dim ng_reason As String = String.Empty
            For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                    ng_reason &= chkNg_Reason.Items(i).Value & "/"
                End If
            Next
            ng_reason = ng_reason.Substring(0, ng_reason.Length - 1)
            Dim rtn As Integer = objGtProcedureOperatedNgDetails.save(ng_reason, dgv.SelectedRows(0).Cells("sys_id").Value.ToString())
            If rtn <> -2 Then
                MsgBox("保存成功")
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    chkNg_Reason.Items(i).CheckState = CheckState.Unchecked
                Next
                setData()
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            If dgv.SelectedRows(0).Cells("oper_type").Value.ToString() = "0" Then
                objReasonMst.setMstChkList(chkNg_Reason, "gjb", current_procedure_No)
            Else
                objReasonMst.setMstChkList(chkNg_Reason, "flb", current_procedure_No)
            End If
        End If
    End Sub
End Class